package com.black.cat.jvm.classfile.attribute;


import com.black.cat.jvm.classfile.ClassReader;
import com.black.cat.jvm.classfile.constantpool.ConstantPool;

import java.util.Arrays;

/**
 * @Author blackcat
 * @create 2021/8/11 20:40
 * @version: 1.0
 * @description:
 * ConstantValue_attribute {
 * u2 attribute_name_index;
 * u4 attribute_length;//2
 * u2 constantvalue_index;//常量池索引
 * }
 */
public class ConstantValueAttribute implements AttributeInfo {

    private long attributeLength;

    //具体指向哪种常量因字段类型而异。
    private int constantValueIndex;

    public ConstantValueAttribute(long attrLen) {
        this.attributeLength = attrLen;
    }

    @Override
    public void readInfo(ClassReader reader) {
        constantValueIndex = reader.nextU2ToInt();
    }

    public int constantValueIdx(){
        return this.constantValueIndex;
    }

    @Override
    public String toString() {
        return "ConstantValueAttribute{" +
                "attributeLength=" + attributeLength +
                "constantValueIndex=" + constantValueIndex +
                "}";
    }
}
